package com.qiaofang.housewarehouse.service.compose;

import com.qiaofang.housewarehouse.dao.domain.EsHswhSaleHouse;
import com.qiaofang.housewarehouse.dao.domain.HswhSaleHouse;
import com.qiaofang.housewarehouse.stub.bean.HswhSaleHouseDetailDTO;
import com.qiaofang.housewarehouse.stub.bean.HswhSaleHouseListDTO;
import com.qiaofang.housewarehouse.stub.bean.HswhSaleHouseListEntity;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class HswhSaleHouseCompose {
    public static List<HswhSaleHouseListDTO> composeListDTO(List<HswhSaleHouse> list) {
        List<HswhSaleHouseListDTO> dtoList = new ArrayList<>();
        if (CollectionUtils.isEmpty(list)) {
            return dtoList;
        }
        for (HswhSaleHouse DO : list) {
            HswhSaleHouseListDTO dto = new HswhSaleHouseListDTO();
            BeanUtils.copyProperties(DO, dto);
            if (StringUtils.isNotBlank(DO.getImgs())){
                dto.setImg(true);
            }else{
                dto.setImg(false);
            }
            dtoList.add(dto);
        }
        return dtoList;
    }
    public static List<HswhSaleHouseDetailDTO> composeDetailListDTO(List<HswhSaleHouse> hswhSaleHouses) {
        List<HswhSaleHouseDetailDTO> hswhSaleHouseDetailDTOS = new ArrayList<>();
        if (CollectionUtils.isEmpty(hswhSaleHouses)) {
            return hswhSaleHouseDetailDTOS;
        }
        for (HswhSaleHouse DO : hswhSaleHouses) {
            HswhSaleHouseDetailDTO dto = new HswhSaleHouseDetailDTO();
            BeanUtils.copyProperties(DO, dto);
            hswhSaleHouseDetailDTOS.add(dto);
        }
        return hswhSaleHouseDetailDTOS;
    }
    public static HswhSaleHouseDetailDTO composeDetailDTO(HswhSaleHouse hswhSaleHouse) {
        HswhSaleHouseDetailDTO hswhSaleHouseDetailDTO = new HswhSaleHouseDetailDTO();
        if (null == hswhSaleHouse) {
            return hswhSaleHouseDetailDTO;
        }
        HswhSaleHouseDetailDTO dto = new HswhSaleHouseDetailDTO();
        BeanUtils.copyProperties(hswhSaleHouse, dto);
        return dto;
    }

    public static List<HswhSaleHouseListEntity> composeListHouseListEntity(List<HswhSaleHouse> list) {
        List<HswhSaleHouseListEntity> dtoList = new ArrayList<>();
        if (CollectionUtils.isEmpty(list)) {
            return dtoList;
        }
        for (HswhSaleHouse DO : list) {
            HswhSaleHouseListEntity dto = new HswhSaleHouseListEntity();
            BeanUtils.copyProperties(DO, dto);
            if (StringUtils.isNotBlank(DO.getImgs())){
                dto.setImg(true);
            }else{
                dto.setImg(false);
            }
            dtoList.add(dto);
        }
        return dtoList;
    }

    public static List<HswhSaleHouseListEntity> composeListHouseListEntity1(List<EsHswhSaleHouse> list) {
        List<HswhSaleHouseListEntity> dtoList = new ArrayList<>();
        if (CollectionUtils.isEmpty(list)) {
            return dtoList;
        }
        for (EsHswhSaleHouse DO : list) {
            HswhSaleHouseListEntity dto = new HswhSaleHouseListEntity();
            BeanUtils.copyProperties(DO, dto);
            if("暂无".equals(dto.getHouseType()) || "暂无信息".equals(dto.getHouseType())){
                dto.setHouseType("");
            }
            if("0".equals(dto.getFloor())){
                dto.setFloor("");
            }
            if("暂无".equals(dto.getDirection()) || "暂无信息".equals(dto.getDirection())){
                dto.setDirection("");
            }
            if (StringUtils.isNotBlank(DO.getImgs())){
                dto.setImg(true);
            }else{
                dto.setImg(false);
            }
            dtoList.add(dto);
        }
        return dtoList;
    }
}
